package com.wbase.demo.work

import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.wbase.base.logger.Logger
import java.lang.Exception

class UploadWorker(context: Context, workerParams: WorkerParameters): Worker(context,workerParams) {
    companion object{
        private const val TAG = "UploadWorker"
    }
    override fun doWork(): Result {
        try {
            executeUpload()
        }catch (e: Exception){
            return Result.failure()
        }
        return Result.success()
    }

    private fun executeUpload() {
        // 真正的执行任务
        Logger.i(TAG,">>>>>>>> start executeUpload:${Thread.currentThread().name}")
        Thread.sleep(2000L)
        Logger.i(TAG,">>>>>>>> end executeUpload:${Thread.currentThread().name}")
    }
}